package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.Aptitude;
import com.ruoyi.system.domain.Examine;
import com.ruoyi.system.domain.Materials;
import com.ruoyi.system.service.IAptitudeService;
import com.ruoyi.system.service.IBankService;
import com.ruoyi.system.service.IMaterialsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Loans;
import com.ruoyi.system.service.ILoansService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 贷款Controller
 * 
 * @author ruoyi
 * @date 2021-09-23
 */
@RestController
@RequestMapping("/system/loans")
public class LoansController extends BaseController
{
    @Autowired
    private ILoansService loansService;

    @Autowired
    private IMaterialsService materialsService;

    @Autowired
    private IAptitudeService aptitudeService;

    @Autowired
    private IBankService bankService;

    /**
     * 查询贷款列表
     */
    @PreAuthorize("@ss.hasPermi('system:loans:list')")
    @GetMapping("/list")
    public TableDataInfo list(Loans loans)
    {
        startPage();
        List<Loans> list = loansService.selectLoansList(loans);
        return getDataTable(list);
    }

    /**
     * 查询银行贷款列表
     */
    @PreAuthorize("@ss.hasPermi('system:loans:list')")
    @GetMapping("/bankLoans")
    public TableDataInfo bankLoans(Loans loans)
    {
        startPage();
        List<Loans> list = loansService.selectBankLoansList(loans);
        return getDataTable(list);
    }

    /**
     * 导出贷款列表
     */
    @PreAuthorize("@ss.hasPermi('system:loans:export')")
    @Log(title = "贷款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Loans loans)
    {
        List<Loans> list = loansService.selectLoansList(loans);
        ExcelUtil<Loans> util = new ExcelUtil<Loans>(Loans.class);
        return util.exportExcel(list, "贷款数据");
    }

    /**
     * 查询审批贷款列表
     */
    @PreAuthorize("@ss.hasPermi('system:loans:loan')")
    @GetMapping("/loansById/{eId}")
    public TableDataInfo loanById(@PathVariable Long eId)
    {
        startPage();
        List<Loans> list = loansService.selectLoansById(eId);
        return getDataTable(list);
    }

    /**
     * 查询银行列表
     */
    @GetMapping("/bankName")
    public AjaxResult listComName()
    {
        return AjaxResult.success(bankService.selectBankNames());
    }
    /**
     * 查询贷款列表
     */
    @GetMapping("/loansNo")
    public AjaxResult listLoansNo()
    {
        return AjaxResult.success(loansService.selectLoansNoAll());
    }

    /**
     * 查询审批材料列表
     */
    @PreAuthorize("@ss.hasPermi('system:loans:loan')")
    @GetMapping("/materialsById/{eId}")
    public TableDataInfo materialsById(@PathVariable Long eId)
    {
        startPage();
        List<Materials> list = materialsService.selectMaterialsById(eId);
        return getDataTable(list);
    }
    /**
     * 查询审批资质列表
     */
    @PreAuthorize("@ss.hasPermi('system:loans:loan')")
    @GetMapping("/aptitudeById/{eId}")
    public TableDataInfo aptitudeById(@PathVariable Long eId)
    {
        startPage();
        List<Aptitude> list = aptitudeService.selectAptitudeById(eId);
        return getDataTable(list);
    }

    /**
     * 获取贷款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:loans:query')")
    @GetMapping(value = "/{loaId}")
    public AjaxResult getInfo(@PathVariable("loaId") Long loaId)
    {
        return AjaxResult.success(loansService.selectLoansByLoaId(loaId));
    }

    /**
     * 新增贷款
     */
    @PreAuthorize("@ss.hasPermi('system:loans:add')")
    @Log(title = "贷款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Loans loans)
    {
        return toAjax(loansService.insertLoans(loans));
    }

    /**
     * 修改贷款
     */
    @PreAuthorize("@ss.hasPermi('system:loans:edit')")
    @Log(title = "贷款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Loans loans)
    {
        return toAjax(loansService.updateLoans(loans));
    }

    /**
     * 删除贷款
     */
    @PreAuthorize("@ss.hasPermi('system:loans:remove')")
    @Log(title = "贷款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{loaIds}")
    public AjaxResult remove(@PathVariable Long[] loaIds)
    {
        return toAjax(loansService.deleteLoansByLoaIds(loaIds));
    }
}
